﻿using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF.Core;

namespace WPF.Zero.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window
    {
        private IHostDialogService dialog;

        public MainView(IHostDialogService dialog)
        {
            this.dialog = dialog;
            InitializeComponent();

            ColorZone.MouseMove += (s, e) =>
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    this.DragMove();
                }
            };

            ColorZone.MouseDown += (s, e) =>
            {
                if (e.ClickCount > 1)
                {
                    if (this.WindowState == WindowState.Normal)
                        this.WindowState = WindowState.Maximized;
                    else 
                        this.WindowState = WindowState.Normal;
                }
            }; 
        }

        private void BtnMinClick(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private async void BtnCloseClick(object sender, RoutedEventArgs e)
        {
            var dialogResult = await dialog.Question("提示", "确定要关闭吗？");
            if (dialogResult.Result != ButtonResult.OK)
            {
                return;
            }
            this.Close();
        }

        private void BtnMaxClick(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
                this.WindowState = WindowState.Normal;
            else
                this.WindowState = WindowState.Maximized;
        }
    }
}
